package com.cqjtu.controller;

import java.util.List;

import com.cqjtu.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cqjtu.service.IProjectService;


/**
 * 项目信息Controller
 *
 * @author kk
 * @date 2024-03-03
 */
@RestController
public class ProjectController extends BaseController
{
    @Autowired
    private IProjectService projectService;

    /**
     * 查询项目信息列表
     */
    @GetMapping("/projects")
    public Result list(ProjectVO projectVo)
    {
        startPage(projectVo.getPage(), projectVo.getPageSize());
        List<ProjectVO> list = projectService.selectProjectList(projectVo);
        System.out.println(list);
        return Result.success(getDataTable(list));
    }

    @GetMapping("/projects/selectUnitName")
    public Result listName(ProjectVO projectVo)
    {
        startPage(projectVo.getPage(), projectVo.getPageSize());
        List<ProjectVO> list = projectService.selectProjectList1(projectVo);
        System.out.println(list);
        return Result.success(getDataTable(list));
    }

    /**
     * 获取项目信息详细信息
     */
    @GetMapping(value = "/projects/{projectId}")
    public Result getInfo(@PathVariable("projectId") Integer projectId)
    {
        return Result.success(projectService.selectProjectByProjectId(projectId));
    }

    /**
     * 新增项目信息
     */
    @PostMapping("/projects/insert")
    public Result add(@RequestBody ProjectDto project)
    {
        return projectService.insertProject(project);
    }

    /**
     * 修改项目信息
     */
    @PutMapping("/projects")
    public Result edit(@RequestBody ProjectDto project)
    {
        // return projectService.updateProject(project);
        return projectService.updateProjectByObj(project);
    }

    /**
     * 删除项目信息
     */
    @DeleteMapping("/projects/{projectIds}")
    public Result remove(@PathVariable("projectIds") Long[] projectIds)
    {
        projectService.deleteProjectByProjectIds(projectIds);
        return Result.success();
    }

    /**
     * 删除清单
     * @param manifestIds
     * @return
     */
    @DeleteMapping("/projects/manifest/{manifestIds}")
    public Result removeManifest(@PathVariable("manifestIds") Long[] manifestIds)
    {
        projectService.deleteManifestByManifestIds(manifestIds);
        return Result.success();
    }

    @PutMapping("/projects/manifest")
    public Result updateManifest(@RequestBody Manifest manifest)
    {
        projectService.updateManifest(manifest);
        return Result.success();
    }

    @PostMapping("/projects/manifest/insert")
    public Result insertManifest(@RequestBody Manifest manifest)
    {
        projectService.insertManifest(manifest);
        return Result.success();
    }
}
